package ar.com.blacktobacco;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class RSSChannelAdapter extends ArrayAdapter<RSSItem> {

	private List<RSSItem> items;

	public RSSChannelAdapter(Context context, int textViewResourceId,
			List<RSSItem> items) {
		super(context, textViewResourceId);
		this.items = items;
	}

	@Override
	public int getCount() {
		return items.size();
	}

	@Override
	public RSSItem getItem(int position) {
		return items.get(position);
	}

	@Override
	public int getPosition(RSSItem item) {
		return items.indexOf(item);
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		if (convertView == null) {
			LayoutInflater vi = (LayoutInflater) getContext().getSystemService(
					Context.LAYOUT_INFLATER_SERVICE);
			convertView = vi.inflate(R.layout.item, null);
			RSSItem item = items.get(position);
			TextView title = (TextView) convertView
					.findViewById(R.id.textView1);

			title.setText(item.getTitle());
		}

		return convertView;
	}

}
